import Vue from 'vue'
import Vuex from 'vuex'
Vue.use(Vuex);

//vuex状态监测
let state = {
  loginName: ''
};

//记录登录状态
let mutations = {
  increment (state, staff_id) {
    sessionStorage.setItem("memoryId",staff_id);  //保证当前页面刷新不会是所登录状态丢失
    state.loginName = staff_id;
  },
  reduction (state){
    sessionStorage.removeItem("memoryId");
    state.loginName = '';
  }
};

export default new Vuex.Store({
  state,
  mutations
});

//let router;
/*router.beforeEach((to, from, next) => {

  $store.state.loginName = sessionStorage.getItem('memoryId');//获取本地存储的token

  if (to.meta.requireAuth) {  // 判断该路由是否需要登录权限
    if ($store.state.loginName !== "") {  // 通过vuex state获取当前的token是否存
      next();
    }
    else {
      next({
        path: '/login',
        //query: {redirect: to.fullPath}  // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  }
  else {
    next();
  }
});*/

/*const store = new Vuex.Store({
  state: {
    loginName: ''
  },
  mutations: {
    increment (state, staff_id) {
      state.loginName = staff_id;
    },
    reduction (state){
      state.loginName = '';
    }
  }
});

const state = {
  count: 0
};*/





